import { defHttp } from '/@/utils/http/axios';

enum Api {
  list = '/script/query',
  run = '/script/state',
  check = '/script/check',
  save = '/script/add',
  delete = '/script/delete',
}

/**
 * 列表接口
 * @param params
 */
export const list = (params) => {
  return defHttp.post({ url: Api.list, params });
};
/**
 * 禁用/停止
 * @param params
 */
export const runScript = (params, handleSuccess) => {
  return defHttp.post({ url: Api.run, params }).then(() => {
    handleSuccess();
  });
};
/**
 * 校验
 * @param params
 */
export const check = (params) => {
  return defHttp.post({ url: Api.check, params });
};
/**
 * 保存
 * @param params
 */
export const saveOrUpdateScript = (params) => {
  return defHttp.post({ url: Api.save, params }, { isTransformResponse: false });
};
/**
 * 删除
 */
export const deleteScript = (params, handleSuccess) => {
  return defHttp.post({ url: Api.delete, params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess();
  });
};
